/**
 * Promise顺序执行，解决回调地狱
 */
let state = 1;
// reslove成功，reject失败
let step1 = function(resolve, reject) {
    console.log('第一关，开始')
    if (state == 1) {
        resolve('第一关，完成')
    } else {
        reject('第一关，失败！')
    }
}
let step2 = function(resolve, reject) {
    console.log('第二关，开始')
    if (state == 1) {
        resolve('第二关，完成')
    } else {
        reject('第二关，失败！')
    }
}
let step3 = function(resolve, reject) {
    console.log('第三关，开始')
    state = 2;
    if (state == 1) {
        resolve('第三关，完成')
    } else {
        reject('第三关，失败！')
    }
}

new Promise(step1).
then((val) => {
    console.log(val)
    return new Promise(step2);
})
.then((val) => {
    console.log(val)
    return new Promise(step3);
})
.then((val) => {
    console.log(val)
})